package com.example.triprec.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.example.triprec.R;
import com.gzone.university.adapter.ItemViewHolder;
import com.gzone.university.adapter.ViewAdapter;
import com.gzone.university.utils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

public class ScenicDetailImageAdapter extends ViewAdapter<ScenicDetailImageAdapter.ViewHolder> {

    private final List<Integer> list = new ArrayList<>();

    public ScenicDetailImageAdapter(View view) {
        super(view, 3);
    }

    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_scenic_detail_image, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder) {
        int imageResId = list.get(holder.getAdapterPosition());
        GlideUtils.load(holder.ivScenicImage, imageResId);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setData(List<Integer> list) {
        this.list.clear();
        if (list != null) {
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    public static class ViewHolder extends ItemViewHolder {

        private final ImageView ivScenicImage;

        public ViewHolder(View itemView) {
            super(itemView);
            ivScenicImage = itemView.findViewById(R.id.iv_scenic_image);
        }
    }
}
